package com.briup.test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Stream;

/**
 * @Auther: hjy(lc))
 * @Date: 2022/10/5-10-05-10:48
 * @Description：com.briup.test
 */
public class commoninterfnce {
    public static void main(String[] args) {
        int[] arr = {78,50,23,564,23,452,22,88};

        Integer[] newarr = commoninterfnce.filter(arr, (t) -> t > 50);             //数值大于50才会保留到新数组中
        System.out.println(Arrays.toString(newarr));
    }
    public static Integer[] filter(int[] old, Predicate<Integer> pre){
        List<Integer> list = new ArrayList<>();

        //遍历老数组，符合特征，则添加到新数组
        for (int i : old) {
            if(pre.test(i)){
                list.add(i);     //满足条件，添加进集合
            }
        }
        return list.toArray(new Integer[list.size()]);
    }
}
